package com.njupt.towerssystem.services.impl;

import com.njupt.towerssystem.mapper.ManagersMapper;
import com.njupt.towerssystem.services.PowersService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class PowersServiceImpl implements PowersService {
    private static Logger logger=LoggerFactory.getLogger(PowersServiceImpl.class);
    @Resource
    private ManagersMapper managersMapper;


    @Override
    public void addNewRule(int ruleid,String rulename) {
        Map mp=new HashMap<>();
        mp.put("ruleid",ruleid);
        mp.put("rulename",rulename);
        managersMapper.insertRule(mp);
    }

    @Override
    public void revokeRule(int ruleid, int userid) {
        Map mp=new HashMap<>();
        mp.put("ruleid",ruleid);
        mp.put("userid",userid);
        managersMapper.delRule(mp);
    }

    @Override
    public void grantRule(int ruid,int ruleid, int userid) {
        Map mp=new HashMap<>();
        try {
            mp.put("ruid",ruid);
            mp.put("ruleid",ruleid);
            mp.put("userid",userid);
            //记录了一个错误级别的日志
            managersMapper.addRule(mp);
        } catch (Exception e) {
            logger.error("我发现了错误。。。。。"+mp);
        }
    }
}
